<?php
	class ToolbarsHelper extends HtmlHelper
	{
		/**
		 * Generates toolbar with specified buttons
		 *
		 * @param array $buttons array of buttons. Example: $buttons = array('add_button' => array('image'=>'image.gif', 'text'=>'caption', 'url'=>'url_here'));
		 * @param string $width width of toolbar, default 100%
		 */	
		function Toolbar($buttons, $width='100%')
		{
			echo "<table class='toolbar' cellspacing = '0' cellpadding = '0' border='0' width='".$width."'><tr><td>";
			echo "<table cellspacing = '0' cellpadding = '0' border='0' ><tr><td width = 10>&nbsp&nbsp</td>";
			$i=0;
			foreach ($buttons as $key=>$value)
			{
				if ($i > 0)
				{
					$this->ToolButtonSeparator();
				}
				$this->ToolButton($value[image], $value[text], $value[url], $value[attributes]);
				$i++;
			}
			echo "</tr></table>";
			echo "</td></tr></table>";
			echo "<div class = empty height = '10px'></div>";
		}
		
		private function ToolButton($image, $text, $url, $attributes)
		{
			global $current_controller;
			echo "<td class = 'menubuttons'>";
			if (empty($url)) 
				echo "<a onmouseover='this.style.cursor=\"pointer\"' $attributes class = 'menubuttons' style = 'background-image: url(/./".THEMES.SEPARATOR.$current_controller->theme."/images/".$image.");background-repeat: no-repeat; background-position:left top;'>$text</a>";
			else echo $this->link($url, $text, "$attributes class = 'menubuttons' style = 'background-image: url(/./".THEMES.SEPARATOR.$current_controller->theme."/images/".$image.");background-repeat: no-repeat; background-position:left top;'");
			echo "</td>";
		}
		
		private function ToolButtonSeparator()
		{
			echo "<td align = 'center' width = '5px'>";
			echo $this->img('toolbar_separator.gif', 1, 17);
			echo "</td>";
		}
		
		private function ToolBarSeparator()
		{
			echo "<td align = 'left' width ='5'>";
			echo $this->img('toolbar_bg.gif', 7, 20);
			echo "</td>";
		}

		/**
		 * Generates informational toolbar from an array
		 *
		 * @param array $value_array multidemensial array with [label] and [value] elements
		 */	
		public function ToolbarInfo(array $value_array)
		{
			echo '<table class="eva" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td style="padding: 5px 15px 5px 15px">';
			foreach ($value_array as $value)
			{
				echo "<span class='infoLabel'>".ucfirst($value[label])."</span> - ";
				echo "<span class='infoValue'>".$value[value].'</span> | ';
			}
			echo '</td></tr></tbody></table>';
		}
	}
?>